import time

class Personality(object):
    # Notice that a lot of what this does is "channeling" the 
    # results object.  Middleman? 

    def __init__(self, commentInterval_ms = 5, timer = time.time ):
        self.timesource = timer
        self.lastResult = None
        self.lastGreen = None
        self.lastComment = None
        self.commentInterval = commentInterval_ms

    def update(self, resultList):
        self.lastUpdate = self.timesource()
        self.lastResult = resultList
        if self.isGreen():
            self.lastGreen = self.timesource()

    def msSinceLastGreen(self):
        return self.timesource() - self.lastGreen

    def msSinceLastUpdate(self):
        return self.timesource() - self.lastUpdate

    def isGreen(self):
        result = self.lastResult
        return result.testsRun and \
               not self.hasFailures() and \
               not self.hasErrors()

    def hasFailures(self):
        return self.lastResult.failures > []

    def hasErrors(self):
        return self.lastResult.errors > []


